package com.smh.demo1.a04;

import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;

/**
 * @author shiminghui
 * @date 2025/4/10 20:32
 * @description: TODO
 */
public class Bean1 {
    private static final Logger log = LoggerFactory.getLogger(Bean1.class);
    private Bean2 bean2;

    @Autowired
    private Bean3 bean3;

    public Bean1() {
        log.info("bean1 init");
    }

    @Autowired
    public void setBean2(Bean2 bean2) {
        log.info("autowired: setBean2");
        this.bean2 = bean2;
    }

    @Resource
    public void setBean3(Bean3 bean3) {
        log.info("resource: setBean3");
        this.bean3 = bean3;
    }

    @Autowired
    public void setProperties(@Value("${JAVA_HOME}") String value) {
        log.info("autowired: 注入属性字段:{}", value);
    }

    @PostConstruct
    public void init() {
        log.info("postConstruct: init");
    }

    @PreDestroy
    public void destroy() {
        log.info("preDestroy: destroy");
    }

    @Override
    public String toString() {
        return "Bean1{" +
                "bean2=" + bean2 +
                ", bean3=" + bean3 +
                '}';
    }


}
